package com.cxyd.modules.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cxyd.common.service.impl.CrudServiceImpl;
import com.cxyd.common.utils.ConvertUtils;
import com.cxyd.modules.wms.dao.StockExpiryDao;
import com.cxyd.modules.wms.dto.StockExpiryDTO;
import com.cxyd.modules.wms.entity.StockExpiryEntity;
import com.cxyd.modules.wms.service.StockExpiryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class StockExpiryServiceImpl extends CrudServiceImpl<StockExpiryDao, StockExpiryEntity, StockExpiryDTO> implements StockExpiryService {
    @Override
    public QueryWrapper<StockExpiryEntity> getWrapper(Map<String, Object> params) {
        String reelId = (String) params.get("reelId");
        String contNo = (String) params.get("contNo");
        String spuNo = (String) params.get("spuNo");
        String curPosition = (String) params.get("curPosition");
        String positionType = (String) params.get("positionType");

        QueryWrapper<StockExpiryEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(reelId), "reel_id", reelId);
        wrapper.eq(StringUtils.isNotBlank(contNo), "cont_no", contNo);
        wrapper.eq(StringUtils.isNotBlank(curPosition), "cur_position", curPosition);
        wrapper.eq(StringUtils.isNotBlank(positionType), "position_type", positionType);
        wrapper.like(StringUtils.isNotBlank(spuNo), "spu_no", spuNo);
        return wrapper;
    }

    @Override
    public List<StockExpiryDTO> getList(Map<String, Object> params) {
        List<StockExpiryEntity> page = baseDao.selectList(
                getWrapper(params)
        );

        return ConvertUtils.sourceToTarget(page, StockExpiryDTO.class);
    }
}
